/*
 *     ManagerDaoImpl.java  Copyright (c) 2021. cc01cc. All rights reserved.
 *
 *     This file is part of e-commerce.
 *
 *     e-commerce is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Affero General Public License as published
 *     by the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     e-commerce is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Affero General Public License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package dao;

import pojo.Manager_register;
import pojo.User_register;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author cc01cc
 */
public class ManagerDaoImpl implements ManagerDao{

    @Override
    public Manager_register getLoginManager(Connection connection, String managerName){
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Manager_register manager = null;

        if(connection != null){
            String sql = "select * from e_commerce_db.manager_register where manager_name= ?";

            Object[] params = {managerName};

            try{
                resultSet = BasicDao.execute(connection, sql, params, preparedStatement, resultSet);
                if(resultSet.next()){
                    manager = new Manager_register();
                    manager.setManager_id(resultSet.getInt("manager_id"));
                    manager.setManager_name(resultSet.getString("manager_name"));
                    manager.setManager_pwd(resultSet.getString("manager_pwd"));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return manager;
    }
}
